package Student.Test;

import Student.Dao.StudentDao;
import Student.Dao.SubjectDao;
import Student.Entity.Student;
import Student.Entity.Subject;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Scanner;

public class StudentDaoTest {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        StudentDao st = new StudentDao();
        while (true) {
            System.out.println("请选择您需要的操作：\n1、增加新学生\n2、修改学生信息\n3、分页显示学生信息\n" +
                    "4、根据课程编号查找学生\n5、删除学生信息\n0、退出");
            int chooce = input.nextInt();
            switch (chooce) {
                case 1:
                    System.out.println("请输入新同学的姓名：");
                    String name = input.next();
                    System.out.println("请输入新同学的性别：");
                    String sex = input.next();
                    System.out.println("请输入新同学的电话：");
                    String telephone = input.next();
                    System.out.println("请输入新同学的QQ：");
                    String qq = input.next();
                    System.out.println("请输入新同学的微信：");
                    String wechat = input.next();
                    System.out.println("请输入新同学的年级号：");
                    int grade = input.nextInt();
                    System.out.println("请输入新同学的入学时间：");
                    String enterdate = input.next();
                    System.out.println("请输入新同学的籍贯：");
                    String fromcity = input.next();
                    System.out.println("请输入新同学的生日：");
                    String birthday = input.next();
                    System.out.println("请输入新同学的住址：");
                    String address = input.next();
                    System.out.println("请输入新同学的密码：");
                    String password = input.next();
                    System.out.println("请输入新同学的身份证号码：");
                    String idcard = input.next();
                    int add = st.add(new Student(name, sex, telephone, qq, wechat, grade, Date.valueOf(enterdate), fromcity, Date.valueOf(birthday), address, password, idcard));
                    if (add > 0)
                        System.out.println("增加成功！");
                    else
                        System.out.println("增加失败！");
                    break;
                case 2:
                    System.out.println("请输入需要修改学生的编号：");
                    int id = input.nextInt();
                    System.out.println("请输入新同学的姓名：");
                    String name1 = input.next();
                    System.out.println("请输入新同学的性别：");
                    String sex1 = input.next();
                    System.out.println("请输入新同学的电话：");
                    String telephone1 = input.next();
                    System.out.println("请输入新同学的QQ：");
                    String qq1 = input.next();
                    System.out.println("请输入新同学的微信：");
                    String wechat1 = input.next();
                    System.out.println("请输入新同学的年级号：");
                    int grade1 = input.nextInt();
                    System.out.println("请输入新同学的入学时间：");
                    String enterdate1 = input.next();
                    System.out.println("请输入新同学的籍贯：");
                    String fromcity1 = input.next();
                    System.out.println("请输入新同学的生日：");
                    String birthday1 = input.next();
                    System.out.println("请输入新同学的住址：");
                    String address1 = input.next();
                    System.out.println("请输入新同学的密码：");
                    String password1 = input.next();
                    System.out.println("请输入新同学的身份证号码：");
                    String idcard1 = input.next();
                    int update = st.update(new Student(id,name1, sex1, telephone1, qq1, wechat1, grade1, Date.valueOf(enterdate1), fromcity1, Date.valueOf(birthday1), address1, password1, idcard1));
                    if (update > 0)
                        System.out.println("修改成功！");
                    else
                        System.out.println("修改失败！");
                    break;
                case 3:
                    System.out.println("请输入需要查看第几页：");
                    int page = input.nextInt();
                    System.out.println("请输入显示的行数：");
                    int line = input.nextInt();
                    List<Student> list = st.search(page, line);
                    for (int i = 0; i < list.size(); i++) {
                        System.out.println(list);
                    }
                    break;
                case 4:
                    System.out.println("请输入需要查询的学生编号：");
                    int f = input.nextInt();
                    Student student = st.find(f);
                    if (student != null)
                        System.out.println(student);
                    else
                        System.out.println("未找到您输入编号的学生！");
                    break;
                case 5:
                    System.out.println("请输入需要删除的学生编号：");
                    int d = input.nextInt();
                    int delete = st.delete(d);
                    if (delete == 1)
                        System.out.println("删除成功！");
                    else
                        System.out.println("删除失败！");
                    break;
                case 0:
                    System.out.println("退出！");
                    return;
            }
        }
    }
}
